package cn.icyzx.dao;

import cn.icyzx.exception.AddWorkTagException;
import cn.icyzx.exception.TagException;
import cn.icyzx.models.Tag;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author zk
 * @Date 2017/3/20.
 * @Email 2117251154@qq.com
 */
@Repository("daoTag")
public class DaoTag {

    private static Logger logger = Logger.getLogger(DaoTag.class);

    @Autowired
    WorkMapper workMapper;

    /***
     *  根据名字获取tag标签
     * @param tag
     * @return
     */
    public Tag getTagByName(String tag) throws TagException {
        return workMapper.getTagByName(tag);
    }

    public List<Tag> getTagList() throws TagException {
        return workMapper.getHotTags();
    }

    public void addTag(String tag) throws TagException {
        if (workMapper.addTag(tag) <= 0)
            throw new TagException("添加新tag失败" + tag);
    }

    public void addWorkTagRecord(String wid, String tag) throws AddWorkTagException {
        workMapper.addWorkTagRecord(wid, tag);
    }

}
